package com.mornd.gulimall.cart.utils;

import com.mornd.gulimall.cart.entity.UserInfo;

/**
 * @author: mornd
 * @dateTime: 2023/8/20 - 8:18
 * 同一线程中保存登录用户信息
 */
public class UserHolder {
    private static final ThreadLocal<UserInfo> SESSION_USER_THREAD_LOCAL = new ThreadLocal<>();

    public static void setUser(UserInfo userInfo) {
        SESSION_USER_THREAD_LOCAL.set(userInfo);
    }

    public static UserInfo getUser() {
        return SESSION_USER_THREAD_LOCAL.get();
    }

    public static void remove() {
        SESSION_USER_THREAD_LOCAL.remove();
    }


}
